home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / ingres04.lzh / source / iutil / opencat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1985-01-23  |  2.6 KB  |  119 lines

  1. # include    <ingres.h>
  2. # include    <aux.h>
  3. # include    <opsys.h>
  4. # include    <access.h>
  5. # include    <sccs.h>
  6.  
  7. SCCSID(@(#)opencat.c    8.2    1/15/85)
  8.  
  9. /*
  10. **  OPENCATALOG -- open system catalog
  11. **
  12. **    This routine opens a system catalog into a predetermined
  13. **    cache.  If the catalog is already open, it is not reopened.
  14. **
  15. **    The 'Desxx' struct defines which relations may be opened
  16. **    in this manner and is defined in .../source/aux.h.
  17. **
  18. **    The relation should not be closed after use (except in
  19. **    special cases); however, it should be noclose'd after use
  20. **    if the number of tuples in the catalog may have changed.
  21. **
  22. **    The Desxx structure has an alias field which
  23. **    is the address of the 'Admin' structure cache which holds
  24. **    the relation descriptor.  Thus, an openr need never actually
  25. **    occur.
  26. **
  27. **    The actual desxx structure definition is in the file
  28. **    
  29. **        catalog_desc.c
  30. **
  31. **    which defines which relations can be cached and if any
  32. **    alias descriptors exist for the relations. That file
  33. **    can be redefined to include various caching.
  34. **
  35. **
  36. **    Parameters:
  37. **        name -- the name of the relation to open.  It must
  38. **            match one of the names in the Desxx
  39. **            structure.
  40. **        mode -- just like 'mode' to openr.  If zero, it
  41. **            is opened read-only; if two, it is opened
  42. **            read/write.  In fact, the catalog is always
  43. **            opened read/write, but the flags are set
  44. **            right for concurrency to think that you are
  45. **            using it as you have declared.
  46. **
  47. **    Returns:
  48. **        none
  49. **
  50. **    Side Effects:
  51. **        A relation is (may be) opened.
  52. **
  53. **    Trace Flags:
  54. **        none
  55. */
  56.  
  57. opencatalog(name, mode)
  58. char    *name;
  59. int    mode;
  60. {
  61.     int            i;
  62.     register DESC        *d;
  63.     register char        *n;
  64.     register struct desxx    *p;
  65.     extern struct desxx    Desxx[];
  66.     extern long        CmOfiles;
  67.  
  68.     n = name;
  69.  
  70.     /* find out which descriptor it is */
  71.     for (p = Desxx; p->cach_relname; p++)
  72.         if (sequal(n, p->cach_relname))
  73.             break;
  74.     if (!p->cach_relname)
  75.         syserr("opencatalog: (%s)", n);
  76.  
  77.     d = p->cach_desc;
  78.  
  79.     /* if it's already open, just return */
  80.     if (d->relopn)
  81.     {
  82.         clearkeys(d);
  83.     }
  84.     else
  85.     {
  86.         /* not open, open it */
  87.         if (p->cach_alias)
  88.         {
  89.             acc_init();
  90.             bmove((char *) p->cach_alias, (char *) d, sizeof (*d));
  91.         }
  92.         else
  93.         {
  94.             if ((i = openr(d, OR_WRITE, n)) != 0)
  95.                 syserr("opencatalog: openr(%s) %d", n, i);
  96.         }
  97.  
  98.         /* mark it as an open file */
  99.         CmOfiles |= 1 << d->relfp;
  100.     }
  101.  
  102.     /* determine the mode to mark it as for concurrency */
  103.     switch (mode)
  104.     {
  105.       case OR_READ:    /* read only */
  106.         d->relopn = abs(d->relopn);
  107.         break;
  108.  
  109.       case OR_WRITE:    /* read-write */
  110.         d->relopn = -abs(d->relopn);
  111.         break;
  112.  
  113.       default:
  114.         syserr("opencatalog(%s): mode %d", n, mode);
  115.     }
  116.  
  117.     return;
  118. }
  119.